package com.example.a14110100420.yuejian.Fragment.club;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.a14110100420.yuejian.R;
import com.example.a14110100420.yuejian.WAdapter.club.ReqiClublistAdapter;
import com.example.a14110100420.yuejian.WSerivice.ClubService;
import com.example.a14110100420.yuejian.Wbase.Conast;
import com.example.a14110100420.yuejian.Wbean.club.Clublist;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


/**
 * A simple {@link Fragment} subclass.
 */
public class Renqi_ClubFragment extends Fragment {
    private View view;
    private RecyclerView recyclerView;
    private Intent intent;




    public Renqi_ClubFragment() {
        // Required empty public constructor
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.fragment_renqi__club, null);

        recyclerView = view.findViewById(R.id.club_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        recyclerView.setItemAnimator(new DefaultItemAnimator());

        getClublist();

        return view;
    }

    private void getClublist(){
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Conast.base_Url)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        ClubService clubService = retrofit.create(ClubService.class);
        Call<List<Clublist>> call = clubService.getClublist();
        call.enqueue(new Callback<List<Clublist>>() {
            @Override
            public void onResponse(Call<List<Clublist>> call, Response<List<Clublist>> response) {
                List<Clublist> list = response.body();
                if (response.isSuccessful()){
                    ReqiClublistAdapter adapter =new ReqiClublistAdapter(getActivity(),list);
                    recyclerView.setAdapter(adapter);
                }
            }

            @Override
            public void onFailure(Call<List<Clublist>> call, Throwable t) {

            }
        });
    }

}
